package cn.source.web.controller.rank;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import cn.source.subject.domain.SmSubject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import cn.source.common.annotation.Log;
import cn.source.common.core.controller.BaseController;
import cn.source.common.core.domain.AjaxResult;
import cn.source.common.enums.BusinessType;
import cn.source.rank.domain.Rank;
import cn.source.rank.service.IRankService;
import cn.source.common.utils.poi.ExcelUtil;
import cn.source.common.core.page.TableDataInfo;

/**
 * 专业排名管理Controller
 *
 * @author xuhao
 * @date 2023-12-21
 */
@RestController
@RequestMapping("/rank/rank")
public class RankController extends BaseController
{
    @Autowired
    private IRankService rankService;

    /**
     * 查询专业排名管理列表
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:list')")
    @GetMapping("/list")
    public TableDataInfo list(Rank rank)
    {
        startPage();
        List<Rank> list = rankService.selectRankList(rank);
        return getDataTable(list);
    }

    /**
     * 导出专业排名管理列表
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:export')")
    @Log(title = "专业排名管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Rank rank)
    {
        List<Rank> list = rankService.selectRankList(rank);
        ExcelUtil<Rank> util = new ExcelUtil<Rank>(Rank.class);
        util.exportExcel(response, list, "专业排名管理数据");
    }



    /**
     * 获取专业排名管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(rankService.selectRankById(id));
    }

    /**
     * 新增专业排名管理
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:add')")
    @Log(title = "专业排名管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Rank rank)
    {
        return toAjax(rankService.insertRank(rank));
    }

    /**
     * 修改专业排名管理
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:edit')")
    @Log(title = "专业排名管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Rank rank)
    {
        return toAjax(rankService.updateRank(rank));
    }

    /**
     * 删除专业排名管理
     */
    @PreAuthorize("@ss.hasPermi('rank:rank:remove')")
    @Log(title = "专业排名管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rankService.deleteRankByIds(ids));
    }
}
